﻿using System;
using EnvDTE;
using System.Security.Principal;
using System.Runtime.InteropServices;

namespace CodeCounsel.SharePoint.DevTools.ProjectTypes
{
    public class WizardUtilities
    {
        public static DTE Dte { get; internal set; }

        public static void CheckPermissions()
        {
            if (Environment.OSVersion.Version.Major >= 6)
            {
                WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
                {
                    Marshal.ThrowExceptionForHR(NativeMethods.HResultFromWin32(740));
                }
            }
        }

        public static bool IsSharePointInstalled(DTE dte)
        {
            return SharePointServices.GetProjectService(dte).IsSharePointInstalled;
        }
    }
}
